<!-- home -->
<template>
  <div class="index-container">
    <div v-for="(item, index) in subjectList" :key="index">
      <div class="headline">
        <img class="headline_ico" :src="require('@/assets/images/subject_' + item.id + '.png')" alt />
        <span class="headline_title">{{ item.name }}</span>
      </div>
      <div class="headline_two clearfix">
        <ul class="clearfix">
          <li
            :class="subjectValue == sub.id ? 'active' : ''"
            v-for="(sub, index) in item.children"
            :key="index"
            @click="subClick(sub)"
          >
            <div>
              <span class="headline_two_title">{{ sub.name }}</span>
            </div>
          </li>
        </ul>
      </div>
    </div>
  </div>
</template>

<script>
import { handleTree } from '@/utils'
import { getSubjectList } from '@/api/user'
export default {
  data() {
    return {
      subjectList: [],
      list: [],
      subjectValue: this.$route.query.subject_id || '2'
    }
  },

  computed: {},

  mounted() {
    this.getSubject()
  },
  methods: {
    getSubject() {
      getSubjectList().then(res => {
        this.subjectList = handleTree(res.data)
      })
    },
    subClick(row) {
      this.$router.push({ path: '/register-guide', query: { subject_id: row.id } })
      // this.$router.push({ query: { subject_id: row.id } })
      // this.$router.go(-1)
    }
  }
}
</script>
<style lang="scss" scoped>
.clearfix {
  &:after {
    content: '';
    display: table;
    clear: both;
  }
}
.index-container {
  width: 100%;
  height: 100%;
}
.headline {
  margin-top: 22px;
  display: flex;
  span {
    display: table-cell;
  }
  .headline_ico {
    width: 25px;
    height: 25px;
    background: #e5f4f4;
    border-radius: 50%;
  }
  .headline_title {
    padding-left: 10px;
    font-size: 15px;
    font-weight: bold;
    color: #333333;
    line-height: 30px;
  }
}

.headline_two {
  // margin-top: 5px;
  padding: 0 15px;
  li {
    float: left;
    width: 48%;
    height: 38px;
    margin-top: 10px;
    line-height: 30px;
    text-align: center;
    background: #f6f6f6;
    border-radius: 19px;
    .headline_two_title {
      font-size: 14px;
      font-weight: 500;
      color: #333333;
    }
  }
  li:nth-of-type(odd) {
    float: left;
  }
  li:nth-of-type(even) {
    float: right;
  }
}
.active {
  background: #009697 !important;
  .headline_two_title {
    color: #ffffff !important;
  }
}
</style>
